var api = require('./../../config/api.js');
var app = getApp();
var util = require('./../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: {},
    knightLevel: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadData(options);
  },

  loadData: function(options){
    var that = this;
    if (app.globalData.userInfo){
  
      if (app.globalData.knight){
        this.setData({knightLevel: app.globalData.knight.klId})
      }
  
      
      var url = api.OrderInfo + '/' + app.globalData.userInfo.token + '/' + options.aoId
      if (options.from == 'shop'){
        var url = api.OrderInfo + '/' + app.globalData.userInfo.token + '/' + options.order_sn + "?from=shop"
      }
      
      util.myRequest(url, false, function(data){
        if (data.data.aoType == 'shop') {
          var aoTakeInfo = JSON.parse(data.data.aoTakeInfo);
          data.data.stName = aoTakeInfo.shop_name;
          data.data.ceName = aoTakeInfo.goods_name;
          if (aoTakeInfo.specification_name){

          }
          data.data.aaMobile = aoTakeInfo.cellphone;
          if (that.data.knightLevel==4 || that.data.knightLevel==0){
            data.data.aaHideMobile = aoTakeInfo.cellphone.substr(0, 3) + '****' + aoTakeInfo.cellphone.substr(7);
          }else{
            data.data.aaHideMobile = aoTakeInfo.cellphone
          }
          
          data.data.aaAddress = aoTakeInfo.address;
          data.data.ssName = '';
          data.data.aaName = aoTakeInfo.user_name;
          data.data.aoMemo = aoTakeInfo.remark
          data.data.shopName = aoTakeInfo.shop_name
          data.data.shopAddress = aoTakeInfo.shop_address
          data.data.shopPhone = aoTakeInfo.shop_phone
          data.data.goodsList = aoTakeInfo.goods
        }
      console.log(data.data)
        that.setData({detail: data.data});
      });
    }else{
      setTimeout(function(){
        that.loadData(options)
      }, 200);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return app.globalData.shareInfo;
  },

  /**
   * 拨打骑士电话
   */
  callKnight: function(){
    wx.makePhoneCall({
      phoneNumber: this.data.detail.knight.uMobile 
    })
  },

  /**
   * 拨打客户电话
   */
  callCustomer: function () {
    var that = this;
    if (this.data.knightLevel!=4 && this.data.knightLevel!=0){
      wx.makePhoneCall({
        phoneNumber: that.data.detail.aaMobile
      })
    }
  },
  callCustomer2: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.detail.shopPhone
    })
  },

  /**
   * 返回
   */
  goBack: function () {
    wx.navigateBack({
      delta: 1
    })
  },

  goUpload: function () {
    wx.navigateTo({
      url: './../uploadImg/uploadImg?isView=1&isUser=1&id='+this.data.detail.aoCode + '&uId=' + this.data.detail.uId
    })
  },
})